home *** CD-ROM | disk | FTP | other *** search
- #include <StdLib.h>
- #include "CursorBalloon.h"
- #include "FabWmemman.h"
- #include "FabWList.h"
-
- typedef struct fabwlist FabWList;
-
- struct fabwlist {
- FabWList *ptr; // next in list
- DialogRef d; // OS window
- FabWindowPtr f; // my data
- };
-
- static FabWList startOfWList = { nil, nil, nil };
- static UInt32 gWindowCount = 0;
-
- #if !defined(FabNoSegmentDirectives)
- #pragma segment Main
- #endif
-
-
- FabWindowPtr AddWindowToList(DialogRef d)
- {
- FabWList *newElem;
-
- newElem = ffcalloc(sizeof(struct fabwlist) + sizeof(struct FabWindowRec));
- if (newElem == nil)
- return nil;
- else {
- newElem->ptr = startOfWList.ptr;
- startOfWList.ptr = newElem;
-
- newElem->d = d;
- if (GetWindowKind(d) != kDialogWindowKind)
- SetWindowKind(d, kFabWindowClass);
-
- //newElem->f = ffcalloc(sizeof(struct FabWindowRec));
- newElem->f = (FabWindowPtr)(newElem + 1);
- Zones(newElem->f) = (RgnBalloonCursHandle)NewHandle(0);
- newElem->f->cntlList = NewHandle(0);
- // other initializations not needed because we allocate the structure with ffcalloc
- ++gWindowCount;
- }
- return newElem->f;
- }
-
- void RemoveWindowFromList(DialogRef d)
- {
- FabWList *newElem = &startOfWList;
- register RgnBalloonCursHandle tempH;
- register RgnBalloonCursPtr spanPtr;
- register unsigned long i;
-
-
- while (newElem->ptr) {
- if (newElem->ptr->d == d) {
- tempH = Zones(newElem->ptr->f);
- HLock((Handle)tempH);
- spanPtr = *tempH;
-
- for (i = 0; i < NumObjects(newElem->ptr->f); i++, spanPtr++) {
- DisposeRgn(spanPtr->zoneLocal);
- DisposeRgn(spanPtr->zoneGlobal);
- // we do nothing with the CursHandles since they might be system cursors
- }
- DisposeHandle((Handle)tempH);
- DisposeHandle(newElem->ptr->f->cntlList);
- // the caller knows whether CloseWindow or CloseDialog is to be called
- // ffree(newElem->ptr->f);
- { FabWList *tmp;
- tmp = newElem->ptr->ptr;
- ffree(newElem->ptr);
- newElem->ptr = tmp;
- }
- --gWindowCount;
- break;
- }
- newElem = newElem->ptr;
- }
- }
-
- FabWindowPtr GetFabWindowPtr(DialogRef d)
- {
- FabWList *newElem = startOfWList.ptr;
-
- if (d) {
- while (newElem) {
- if (newElem->d == d) {
- return newElem->f;
- }
- newElem = newElem->ptr;
- }
- }
- return nil;
- }
-
- void ForEachWindowDo(void (*actProc)(DialogRef))
- {
- DialogRef d;
- FabWList *newElem = startOfWList.ptr;
-
- while (newElem) {
- /* if (newElem->d == d) {
- return newElem->f;
- }*/
- d = newElem->d;
- newElem = newElem->ptr;
- actProc(d);
- }
-
- }
-
- UInt32 GetWindowCount(void)
- {
- return gWindowCount;
- }
-
- #if !defined(FabNoSegmentDirectives)
- #pragma segment Init
- #endif
-
- void InitFabWListManager(void)
- {
- ffree(fmalloc(sizeof(struct fabwlist)));
- }
-
-
- // check out the last #pragma segment !!!!!
-